// 用户数据导入脚本
// 在MongoDB中执行：
// use job_market
// load("/path/to/users.js")

// 清空原有集合
db.users.drop();

// 创建序列集合
db.database_sequences.drop();
db.database_sequences.insertOne({
  _id: "user_sequence",
  seq: 0
});

// 创建自增ID的函数
function getNextSequence(name) {
  var ret = db.database_sequences.findAndModify({
    query: { _id: name },
    update: { $inc: { seq: 1 } },
    new: true
  });
  return ret.seq;
}

// 创建用户数据
const testUsers = [
  {
    _id: getNextSequence("user_sequence").toString(),
    username: "admin",
    password: "admin123",
    email: "admin@example.com",
    realName: "管理员",
    age: 30,
    gender: "男",
    education: "硕士",
    major: "计算机科学",
    experience: 5,
    skills: ["Java", "Spring", "MongoDB", "Redis"],
    preferredCity: "北京",
    preferredPosition: "技术经理",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png", // 默认头像
    createTime: new Date(),
    updateTime: new Date()
  },
  {
    _id: getNextSequence("user_sequence").toString(),
    username: "zhangsan",
    password: "123456",
    email: "zhangsan@example.com",
    realName: "张三",
    age: 25,
    gender: "男",
    education: "本科",
    major: "软件工程",
    experience: 2,
    skills: ["Java", "Spring Boot", "MySQL", "Vue.js"],
    preferredCity: "上海",
    preferredPosition: "后端开发工程师",
    avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
    createTime: new Date(),
    updateTime: new Date()
  },
  {
    _id: getNextSequence("user_sequence").toString(),
    username: "lisi",
    password: "123456",
    email: "lisi@example.com",
    realName: "李四",
    age: 28,
    gender: "女",
    education: "本科",
    major: "计算机科学与技术",
    experience: 3,
    skills: ["JavaScript", "React", "Node.js", "CSS"],
    preferredCity: "广州",
    preferredPosition: "前端开发工程师",
    avatar: "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png",
    createTime: new Date(),
    updateTime: new Date()
  },
  {
    _id: getNextSequence("user_sequence").toString(),
    username: "wangwu",
    password: "123456",
    email: "wangwu@example.com",
    realName: "王五",
    age: 32,
    gender: "男",
    education: "硕士",
    major: "人工智能",
    experience: 7,
    skills: ["Python", "TensorFlow", "机器学习", "数据分析"],
    preferredCity: "深圳",
    preferredPosition: "AI工程师",
    avatar: "https://cube.elemecdn.com/d/e2/01f1429fdacd46f86a4c665a5ed26png.png",
    createTime: new Date(),
    updateTime: new Date()
  },
  {
    _id: getNextSequence("user_sequence").toString(),
    username: "zhaoliu",
    password: "123456",
    email: "zhaoliu@example.com",
    realName: "赵六",
    age: 24,
    gender: "女",
    education: "本科",
    major: "数据科学",
    experience: 1,
    skills: ["Python", "Pandas", "数据可视化", "SQL"],
    preferredCity: "北京",
    preferredPosition: "数据分析师",
    avatar: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
    createTime: new Date(),
    updateTime: new Date()
  }
];

// 批量插入数据
db.users.insertMany(testUsers);

// 输出结果
print("用户数据导入成功，共导入 " + testUsers.length + " 条记录");

// 创建用户名的唯一索引
db.users.createIndex({ "username": 1 }, { unique: true });

// 创建邮箱的唯一索引
db.users.createIndex({ "email": 1 }, { unique: true });

print("索引创建成功"); 